package mappackage

import (
	"fmt"
)

func test1() {
	hash1 := make(map[string]int)

	hash1["cpp"] = 1
	hash1["java"] = 2
	hash1["php"] = 3

	fmt.Println(hash1)
	fmt.Println("key: cpp, value:", hash1["cpp"])
}

func test2() {
	hash1 := map[int]func() int{
		1: func() int { return 10 },
		2: func() int { return 20 },
		3: func() int { return 30 },
	}

	fmt.Println(hash1[1]())
	fmt.Println(hash1[2]())
}

func test3() {
	hash1 := make(map[string][]int)
	hash1["cpp"] = append(hash1["cpp"], 2, 3, 4, 5)
	fmt.Println(hash1)
}

func test4() {
	hash1 := make(map[string]int)
	hash1["cpp"] = 0
	value, ok := hash1["cpp"]
	fmt.Println(value, ok)
	fmt.Println(hash1["cpp"])
	fmt.Println(hash1["java"])
}

func test5CheckExist(key string, hash1 map[string]int) {
	if value, ok := hash1[key]; ok {
		fmt.Println(value)
	} else {
		fmt.Println("不存在", key)
	}
}

func test5() {
	hash1 := make(map[string]int)
	hash1["cpp"] = 0
	hash1["java"] = 1
	test5CheckExist("cpp", hash1)
	test5CheckExist("cpp1", hash1)
}

func test6() {
	hash1 := make(map[string]int)
	hash1["cpp"] = 1
	hash1["java"] = 1
	delete(hash1, "cpp")
	delete(hash1, "cpp1")
	if value, ok := hash1["cpp"]; ok {
		fmt.Println(value)
	} else {
		fmt.Println("not found")
	}
}

func test7() {
	s := make([]map[string]int, 5)
	for i := range s {
		s[i] = make(map[string]int)
	}
}

func Test() {
	test6()
}
